<template>
    <div>
        <div class="main-container">
            <el-tabs
                v-model="modelType"
                type="card"
            >
                <el-tab-pane
                    name="baseInfo"
                    label="基本信息"
                >
                    <base-info
                        v-if="isReady"
                        :orders="orders"
                    > </base-info>
                </el-tab-pane>
                <el-tab-pane
                    name="consultationBiopsyView"
                    label="病理信息"
                >
                    <span slot="label">
                        病理信息
                        <el-badge
                            v-if="pathologicalInformationCornerLabel > 0"
                            :value="pathologicalInformationCornerLabel"
                            class="tab-content-badge"
                        ></el-badge>
                    </span>
                    <ConsultationBiopsyView
                        v-if="isReady"
                        :orders="orders"
                    > </ConsultationBiopsyView>
                </el-tab-pane>
                <el-tab-pane
                    name="pathologyView"
                    label="切片列表"
                >
                    <span slot="label">
                        切片列表
                        <el-badge
                            v-if="sectionListCornerLabel > 0"
                            :value="sectionListCornerLabel"
                            class="tab-content-badge"
                        ></el-badge>
                    </span>
                    <consultation-pathologyView
                        v-if="isReady"
                        :orders="orders"
                    > </consultation-pathologyView>
                </el-tab-pane>
                <el-tab-pane
                    name="opinion"
                    label="会诊报告"
                >
                    <span slot="label">
                        会诊报告
                        <el-badge
                            v-if="consultationAdviceCornerLabel > 0"
                            :value="consultationAdviceCornerLabel"
                            class="tab-content-badge"
                        ></el-badge>
                    </span>
                    <consultation-opinion
                        v-if="isReady"
                        :orders="orders"
                    >
                    </consultation-opinion>
                </el-tab-pane>
            </el-tabs>
        </div>
    </div>
</template>

<script>
import BaseInfo from '@/templates/share/ConsultationInfoView'
import ConsultationOpinion from '@/templates/share/ConsultationOpinion'
import ConsultationPathologyView from '@/templates/share/ConsultationPathologyView'
import ConsultationBiopsyView from '@/templates/share/ConsultationBiopsyView'
export default {
  name: 'shareIndex',
  components: {
    BaseInfo,
    ConsultationOpinion,
    ConsultationPathologyView,
    ConsultationBiopsyView
  },
  data() {
    return {
      modelType: 'baseInfo',
      orders: null,
      isReady: false,
      pathologicalInformationCornerLabel: 0,
      sectionListCornerLabel: 0,
      consultationAdviceCornerLabel: 0
    }
  },
  created() {
    this.getPatientsInfo()
  },
  mounted() {},
  methods: {
    getPatientsInfo() {
      const _this = this
      const uuid = this.$route.params.uuid
      this.$axios({
        method: 'GET',
        url: `/orders/test/get/${uuid}`
      }).then(res => {
        if (res && res.data.code) {
          const result = res.data.data
          _this.orders = result
          _this.isSendDoctor = _this.userName === _this.orders.sendingDoctor ? true : false
          if (_this.orders.patients[0].expertDiagnosis.length > 0) {
            _this.consultationSuggest = _this.orders.patients[0].expertDiagnosis.some(item => {
              return item.isFinal !== 1
            })
          }
          _this.orders.consultationDetailList = []
          _this.orders.consultationDetailList.forEach((t, index) => {
            const detailString = _.get(t, 'detailString', '{}')
            if (detailString) {
              const detailCache = detailString.replace('\\', '')
              _this.orders.consultationDetailList[index].detailJson = JSON.parse(detailCache)
            } else {
              _this.orders.consultationDetailList[index].detailJson = {}
            }
          })
          if (
            _this.orders.serviceStatus == 5 &&
            (_this.orders.ordersStatus == 1 || _this.orders.ordersStatus == 4)
          ) {
            _this.showConfirmButton = true
          } else {
            _this.showConfirmButton = false
          }
          _this.isReady = true
          _this.angleMarker()
        }
      })
    },
    angleMarker() {
      this.sectionListCornerLabel = 0
      this.pathologicalInformationCornerLabel = 0
      this.orders?.patients?.[0].diagnosisHistory?.[0]?.diagnosisDataInfos.forEach(item => {
        if (item.fileType == 0) {
          this.pathologicalInformationCornerLabel += 1
        } else if (item.fileType == 3) {
          this.sectionListCornerLabel += 1
        }
      })
      this.consultationAdviceCornerLabel = 0
      this.orders.patients[0].expertDiagnosis.forEach(item => {
        if (item.detailString != null) {
          this.consultationAdviceCornerLabel += 1
        }
      })
    }
  }
}
</script>

<style scoped></style>